<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>文件上传</title>
    <!--框架必需start-->
    <script type="text/javascript" src="../../libs/js/jquery.js"></script>
    <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
    <script type="text/javascript" src="../../libs/js/framework.js"></script>
    <script type="text/javascript" src="../../libs/js/form/datePicker/WdatePicker.js"></script>
    <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
    <link rel="stylesheet" type="text/css" id="customSkin"/>
    <!--框架必需end-->
    <link rel="stylesheet" type="text/css" href="../../sample_skin/demo/style/style.css"/>

    <script src="../../libs/js/table/quiGrid.js" type="text/javascript"></script>

    <!--基本选项卡start-->
    <script type="text/javascript" src="../../libs/js/nav/basicTab.js"></script>
    <!--基本选项卡end-->

    <!--self开始-->
    <link rel="stylesheet" href="../../assets/css/m_style.css" class="m_style">
    <style>
        #_DialogButtons_0fk{
            text-align: center;
        }
        #_ButtonCancel_0fk{
            display: none;
        }
    </style>
    <!--self结束-->
</head>

<body>
<div class="m_pos">
    <img src="../../assets/images/position.png" alt="" class="m_position">
    <span>当前页面：</span>
    <span class="m_pos_lo">设置></span>
    <span class="m_pos_local">文件上传</span>
</div>
<div class="page_content">
    <div class="infoCard infoCard2">
          <ul class="up_ul">

              <li>
                  <span class="up_text">测报告编号:</span>
                  <div class="up_right">
                      <input type="text" name="number" placeholder="测报告编号" class="up_in">
                  </div>
              </li>
              <li>
                  <span class="up_text">有效期起始时间:</span>
                  <div class="up_right">
                      <input type="text"  name="start_date" placeholder="有效期起始时间"  class="up_in date">
                  </div>
              </li>
              <li>
                  <span class="up_text">有效期结束时间:</span>
                  <div class="up_right">
                      <input type="text"  name="end_date" placeholder="有效期结束时间" class="up_in date">
                  </div>
              </li>
              <li>
                  <span class="up_text">防雷检测报告上传:</span>
                  <div class="up_check">
                      <!--上传的文件-->
                          <input type="file" name="file" placeholder="未选择上传文件" id="cjo" >

                  </div>
              </li>
              <li>
                  <div class="up_check">
                      <div class="up_in_box" onclick="choseFile()">上传
                      </div>
                  </div>
              </li>
          </ul>
    </div>
</div>

<script type="text/javascript">

    var ctx="http://www.chinalightning.com.cn/api/upload_file/";
    function  choseFile() {
        var formData = new FormData();
        if (!$(":file")[0].files[0]){
            alert("未选择文件！")
            return;
        }else
        formData.append("file",$(":file")[0].files[0]);


        var obj=$("input[type='text']");
        for (let i=0 ;i<obj.length;i++){

            var ob=obj[i];

            if (ob.value =='' ){

                alert(ob.placeholder+"为空");
                return;
            }
            formData.append(ob.name,ob.value);
        }

        $.ajax({
            type: "POST",
            url: ctx,
            data: formData,
            processData: false,
            contentType: false,
            success: function (res) {
                if (res.message==200)
                    alert("上传成功！")
                else
                    alert("上传失败,"+res+"!")
            }
        });


    }
</script>
</body>

</html>
